import request from './request.js';
import { storeToRefs } from 'pinia';
import { useCodeStore } from '@/stores/code.js';

export const getIpData = () => {
  const store = useCodeStore();
  const { mykey,ip } = storeToRefs(store);
  return request({
    method: 'GET',
    url: `/ip?${ip.value ? 'ip=' + ip.value + '&' : ''}key=${mykey.value}`
  });
};

export const getadcodeData=()=>{
    const store = useCodeStore();
    const { IpCity,mykey} = storeToRefs(store);
    return request({
        method: 'GET',
        url: `/geocode/geo?address=${IpCity.value}&key=${mykey.value}`
    });
} 

export const getweatherData=(data)=>{
    const store = useCodeStore();
    const { IpCityad,mykey} = storeToRefs(store);
    return request({
        method: 'GET',
        url: `/weather/weatherInfo?city=${IpCityad.value}&key=${mykey.value}&extensions=${data}`
    });
} 
 
export const getnowadcodeData=()=>{
    const store = useCodeStore();
    const { nowcity,mykey} = storeToRefs(store);
    return request({
        method: 'GET',
        url: `/geocode/geo?address=${nowcity.value}&key=${mykey.value}`
    });
} 

export const getnowweatherData=(data)=>{
    const store = useCodeStore();
    const { nowadcode,mykey} = storeToRefs(store);
    return request({
        method: 'GET',
        url: `/weather/weatherInfo?city=${nowadcode.value}&key=${mykey.value}&extensions=${data}`
    });
} 